$(function(){
	initTables();
	if(typeof(_param_id)!='undefined' && _param_id.length > 0){
		_set_lable_text  ('#_loan_detail li span','name',('sys/Loan/findByPk?pks=' + _param_id),true);
		_set_lable_text ('#_contract_detail li span','name',('loan/ContractManage/findLoanContractByLoanId?loanId=' + _param_id),true);
		_set_lable_text ('#_pay_detail li span','name',('loan/ContractManage/findLoanPayByLoanId?loanId=' + _param_id),true);
	}
});

var initTables = function(){
	$('#bank_enterprise').dataTable({
		"bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示
        "bServerSide" : true, //是否启动服务器端数据导入
        "bStateSave" : false, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态
        "bJQueryUI" : true, //是否使用 jQury的UI theme
        //"aLengthMenu" : [5, 10, 15], //更改显示记录数选项
        "iDisplayLength" : 10, //默认显示的记录数
        "bAutoWidth" : true, //是否自适应宽度 update
        "bScrollCollapse" : false, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变
        "bPaginate" : false, //是否显示（应用）分页器
        "bInfo" : false, //是否显示页脚信息，DataTables插件左下角显示记录数
        "sPaginationType" : "full_numbers", //详细分页组，可以支持直接跳转到某页
        "bSort" : false, //是否启动各个字段的排序功能
        //"aaSorting" : [[1, "ASC"]], //默认的排序方式，第3列，升序排列
        "bFilter" : false, //是否启动过滤、搜索功能
	    "sAjaxSource":parent.basePath+"loan/ContractManage/findBankListByLoanId",
        "fnServerData":function( sSource, aoData, fnCallback ) {
            aoData.push({'name':'beanProxy[loanId]','value':_param_id});  
            aoData.push({'name':'beanProxy[enable]','value':0});  
                $.ajax( {
                        type: "POST", 
                        url: sSource, 
                        cache : false,
                        dataType : "json",
        	                data : aoData, 
        	                success: function(resp) {
        	                	if(resp && resp.state == 200){
        	                		fnCallback(resp.datagrid);
        	                		return false;
        	                	}
        	                	fnCallback(null);
        	            }
        	        });
        },  //自定义数据获取函数
        
		"aoColumns" : [{
			"mDataProp" : "bankAccount",
			"sTitle" : "账户名",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		},{
			//Client_Bank_Type_Code
			"mDataProp" : "bankType",
			"sTitle" : "银行卡类型",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
			      return SYS_BASE_DATA['Client_Bank_Type_Code'][data];
			    }
		}, {
			//Client_Bank_Name_Code
			"mDataProp" : "bankName",
			"sTitle" : "银行名称",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
			      return SYS_BASE_DATA['Client_Bank_Name_Code'][data];
			    }
		}, {
			"mDataProp" : "bankBranch",
			"sTitle" : "银行所属分行",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "bankNumber",
			"sTitle" : "银行帐号",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			//Client_Bank_Main_Status_Code
			"mDataProp" : "bankMainStatus",
			"sTitle" : "是否为主帐号",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
			      return SYS_BASE_DATA['Client_Bank_Main_Status_Code'][data];
			    }
		}
		
		],
		"oLanguage": {
            "sUrl":parent.basePath+"static_resources/language/lang-cn.txt" //这个是国际化，也就是汉化的各种文字数据源，写对url就行了
        }
	});
	
	$('#guarantee_enterprise').dataTable({
		"bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示
        "bServerSide" : true, //是否启动服务器端数据导入
        "bStateSave" : false, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态
        "bJQueryUI" : true, //是否使用 jQury的UI theme
        //"aLengthMenu" : [5, 10, 15], //更改显示记录数选项
        "iDisplayLength" : 10, //默认显示的记录数
        "bAutoWidth" : true, //是否自适应宽度 update\
        "bScrollCollapse" : false, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变
        "bPaginate" : false, //是否显示（应用）分页器
        "bInfo" : false, //是否显示页脚信息，DataTables插件左下角显示记录数
        "sPaginationType" : "full_numbers", //详细分页组，可以支持直接跳转到某页
        "bSort" : false, //是否启动各个字段的排序功能
        //"aaSorting" : [[1, "ASC"]], //默认的排序方式，第3列，升序排列
        "bFilter" : false, //是否启动过滤、搜索功能
	    "sAjaxSource":parent.basePath+"sys/LoanGuarantee/list",
        "fnServerData":function ( sSource, aoData, fnCallback ) {
    		//var array = $("#_form_search_default").serializeArray();
    		//array.push({'name':'beanProxy[loanStatus_GreaterThanOrEqualTo]','value':5});
    		aoData .push({'name':'beanProxy[loanId]','value':_param_id});
    		aoData .push({'name':'beanProxy[enable]','value':0})
    	        $.ajax( {
    	                type: "POST", 
    	                url: sSource, 
    	                cache : false,
    	                dataType : "json",
    	                data : aoData, 
    	                success: function(resp) {
    	                	if(resp && resp.state == 200){
    	                		fnCallback(resp.datagrid);
    	                		return false;
    	                	}
    	                	fnCallback(null);
    	            }
    	        });
    },  //自定义数据获取函数
        
		"aoColumns" : [
		{
			"mDataProp" : "id",
			"sTitle" : "操作",
			"sDefaultContent" : "",
			"sClass" : "center",
			"sWidth":"100px",
			"mRender": function (data, display, row) {
				return '<a href="javascript:look('+row.id+')" class="tablelink">查看</a>';
				}
		},{
			"mDataProp" : "guaranteeMode",
			"sTitle" : "担保方式",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
			      return SYS_BASE_DATA['Loan_Guarantee_Mode_Code'][data];
			    }
		},{
			//Client_Bank_Type_Code
			"mDataProp" : "guaranteeType",
			"sTitle" : "抵押物类型",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
			      return SYS_BASE_DATA['Loan_Guarantee_Type_Code'][data];
			    }
		}, {
			//Client_Bank_Name_Code
			"mDataProp" : "guaranteeGoods",
			"sTitle" : "物品名称/公司名",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
			      return data;
			    }
		}, {
			"mDataProp" : "guaranteePossessor",
			"sTitle" : "所有权人名称",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		}
		
		],
		"oLanguage": {
            "sUrl":parent.basePath+"static_resources/language/lang-cn.txt" //这个是国际化，也就是汉化的各种文字数据源，写对url就行了
        }
	});
	
};


/*
var look = function(id){
		var aData = $('#guarantee_enterprise').dataTable().fnGetData();
		$.each(aData,function(index,node){
			if(node.id==id){
				_set_lable_text = ('#guarantee_info li td span','name',(''),true,node);
				return;
			}
		});
};
*/
var look = function(id){
	var aData = $('#guarantee_enterprise').dataTable().fnGetData();
	$.each(aData,function(index,node){
		if(node.id==id){
			_set_lable_text = ('#guarantee_info li span','name',(''),true,node);
			return;
			
		}
	});
};

var loan_review = function(){
	$.dialog.confirm('确定复核吗？', function(){
		$.ajax({
	       	url:'sys/LoanExt/review',
	    	data:{pks:_param_id},
	    	type:'post',
	    	dataType:'json',
	    	success:function(result){
	    	        if(typeof(result)!='undefined' && typeof(result.state)!='undefined' && result.state == "200"){
	    	        	$.dialog.alert('复核成功!',function(){
	    	        	});
	    	        	top._do_goto_right('jsp/loan/loan_check_list.jsp');
	    	        }else{
	    	        	$.dialog.alert('复核失败!');
	    	        }
	    		}
	        });
	}, function(){
	});
	
};

var reback_contract = function(){
$.dialog.confirm('确定回退到合同吗?', function(){
	$.ajax({
       	url:'sys/LoanExt/reviewBackToloanContract',
    	data:{pks:_param_id},
    	type:'post',
    	dataType:'json',
    	success:function(result){
    	        if(typeof(result)!='undefined' && typeof(result.state)!='undefined' && result.state == "200"){
    	        	$.dialog.alert('回退到合同成功!',function(){
    	        	});
    	        	top._do_goto_right('jsp/loan/loan_check_list.jsp');
    	        }else{
    	        	$.dialog.alert('回退到合同失败!');
    	        }
    		}
        });
}, function(){
//    $.dialog.tips('执行取消操作');
});
};

var reback_check = function(){
	$.dialog.confirm('确定回退到审批吗?', function(){
		$.ajax({
	       	url:'sys/LoanExt/backToApproval',
	    	data:{pks:_param_id},
	    	type:'post',
	    	dataType:'json',
	    	success:function(result){
	    	        if(typeof(result)!='undefined' && typeof(result.state)!='undefined' && result.state == "200"){
	    	        	$.dialog.alert('回退到审批成功!',function(){
	    	        	});
	    	        	top._do_goto_right('jsp/loan/loan_check_list.jsp');
	    	        }else{
	    	        	$.dialog.alert('回退到审批失败!');
	    	        }
	    		}
	        });
	}, function(){
//	    $.dialog.tips('执行取消操作');
	});
};

var goback = function(){
	top._do_goto_right('jsp/loan/loan_check_list.jsp');
};
 

